package com.wx.mall.sys.vo;

import com.wx.mall.sys.entity.Admin;
import com.wx.mall.sys.entity.Permission;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * SpringSecurity需要的用户详情对象
 */
public class AdminDetailsVo implements UserDetails {

    private Admin admin;
    private List<Permission> permissionList;

    public AdminDetailsVo(Admin admin) {
        this.admin = admin;
    }

    public AdminDetailsVo(Admin admin, List<Permission> permissionList) {
        this.admin = admin;
        this.permissionList = permissionList;
    }

//    @Override
//    public Collection<? extends GrantedAuthority> getAuthorities() {
//        //返回当前用户的权限
//        return permissionList.stream()
//                .filter(permission -> permission.getValue()!=null)
//                .map(permission ->new SimpleGrantedAuthority(permission.getValue()))
//                .collect(Collectors.toList());
//    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return admin.getPassword();
    }

    @Override
    public String getUsername() {
        return admin.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return admin.getIsEnabled().equals(1);
    }
}
